

<h1>商品</h1>

<%if is_admin==1 %>

  <table style="width:100%">
    <thead>
      <tr>
      <th>商品名称</th>
      <th>价格</th>
      <th>数量</th>
      <th>备注</th>
        <th colspan="4">操作</th>
      </tr>
    </thead>

    <tbody>
    <% @products.each do |product| %>
      <tr>
        <td><%= product.name %></td>
        <td><%= product.price %></td>
        <td><%= product.amount %></td>
        <td><%= product.remark %></td>
        <td><%= button_to "加入购物车","/baskets/#{product.id}", remote: true %></td>
        <td><%= link_to '查看', product %></td>
        <td><%= link_to '编辑', edit_product_path(product) %></td>
        <td><%= link_to '删除', product, method: :delete, data: { confirm: '确认删除?' } %></td>
      </tr>
    <% end %>
  </tbody>
  </table>
<% else %>
  <table style="width:100%">
    <thead>
      <tr>
        <th>商品名称</th>
        <th>价格</th>
        <th>数量</th>
        <th>备注</th>
        <th colspan="3">operate</th>
      </tr>
    </thead>

    <tbody>
      <% @products.each do |product| %>
        <tr>
          <td><%= product.name %></td>
          <td><%= product.price %></td>
          <td><%= product.amount %></td>
          <td><%= product.remark %></td>
          <td><%= link_to '查看', product %></td>
          <td><%= button_to "加入购物车","/users/#{product.id}", remote: true %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% end %>

<%= link_to '新建商品', new_product_path %>
